<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: User</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">User</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/app/models/user_rb.html">
                app/models/user.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                ActiveRecord::Base
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000018">authenticate</a>&nbsp;&nbsp;
      <a href="#M000020">courses</a>&nbsp;&nbsp;
      <a href="#M000021">has_course?</a>&nbsp;&nbsp;
      <a href="#M000022">search</a>&nbsp;&nbsp;
      <a href="#M000019">to_s</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">password</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000018" class="method-detail">
        <a name="M000018"></a>

        <div class="method-heading">
          <a href="#M000018" class="method-signature">
          <span class="method-name">authenticate</span><span class="method-args">(username, password)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
checks for successful authentication with a <tt>username</tt> and
<tt>password</tt>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000018-source">
<pre>
    <span class="ruby-comment cmt"># File app/models/user.rb, line 29</span>
29:   <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">authenticate</span>(<span class="ruby-identifier">username</span>, <span class="ruby-identifier">password</span>)
30:     <span class="ruby-identifier">find</span>(<span class="ruby-identifier">:first</span>, 
31:       <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> {<span class="ruby-identifier">:username</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">username</span>, <span class="ruby-identifier">:password_hash</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">SHA1</span>.<span class="ruby-identifier">hexdigest</span>(<span class="ruby-identifier">password</span>)}
32:     )
33:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000022" class="method-detail">
        <a name="M000022"></a>

        <div class="method-heading">
          <a href="#M000022" class="method-signature">
          <span class="method-name">search</span><span class="method-args">(query)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
finds users by first_name, last_name, username, or email
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000022-source">
<pre>
    <span class="ruby-comment cmt"># File app/models/user.rb, line 65</span>
65:   <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">search</span>(<span class="ruby-identifier">query</span>)
66:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">query</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;&quot;</span>
67:       <span class="ruby-keyword kw">return</span> []
68:     <span class="ruby-keyword kw">end</span>
69:       
70:     <span class="ruby-identifier">terms</span> = <span class="ruby-identifier">query</span>.<span class="ruby-identifier">split</span>
71:     <span class="ruby-identifier">fields</span> = [<span class="ruby-value str">'first_name'</span>, <span class="ruby-value str">'last_name'</span>, <span class="ruby-value str">'username'</span>, <span class="ruby-value str">'email'</span>]
72:     
73:     <span class="ruby-identifier">fields</span>.<span class="ruby-identifier">collect!</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">field</span><span class="ruby-operator">|</span> <span class="ruby-identifier">field</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">&quot; LIKE ?&quot;</span>}
74:     
75:     <span class="ruby-identifier">query_string_short</span> = <span class="ruby-identifier">fields</span>.<span class="ruby-identifier">join</span> <span class="ruby-value str">&quot; OR &quot;</span>
76:     
77:     <span class="ruby-identifier">query_string</span> = []
78:     
79:     <span class="ruby-identifier">terms</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">term</span><span class="ruby-operator">|</span> <span class="ruby-identifier">query_string</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">query_string_short</span>}
80:     
81:     <span class="ruby-identifier">conditions</span> = [<span class="ruby-identifier">query_string</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot; AND &quot;</span>),]
82:     
83:     <span class="ruby-identifier">terms</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">term</span><span class="ruby-operator">|</span> <span class="ruby-identifier">fields</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">field</span><span class="ruby-operator">|</span> <span class="ruby-identifier">conditions</span>.<span class="ruby-identifier">push</span> <span class="ruby-value str">'%'</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">term</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'%'</span> } }
84:     
85:     <span class="ruby-identifier">users</span> = <span class="ruby-identifier">find</span> <span class="ruby-identifier">:all</span>, 
86:       <span class="ruby-identifier">:order</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'last_name ASC, first_name ASC'</span>,
87:       <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">conditions</span>,
88:       <span class="ruby-identifier">:limit</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">100</span>
89:     
90:     <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">users</span>   
91:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000020" class="method-detail">
        <a name="M000020"></a>

        <div class="method-heading">
          <a href="#M000020" class="method-signature">
          <span class="method-name">courses</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
returns a combined list of all <a href="User.html#M000020">courses</a>
which this user is taking
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000020-source">
<pre>
    <span class="ruby-comment cmt"># File app/models/user.rb, line 41</span>
41:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">courses</span>
42:     <span class="ruby-identifier">course_list</span> = []
43:     
44:     <span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">collect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">semester</span><span class="ruby-operator">|</span>
45:       <span class="ruby-identifier">course_list</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">semester</span>.<span class="ruby-identifier">cis_courses</span>
46:     <span class="ruby-keyword kw">end</span>
47:     
48:     <span class="ruby-identifier">course_list</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">course_bin</span>.<span class="ruby-identifier">cis_courses</span>
49:     
50:     <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">course_list</span>
51:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000021" class="method-detail">
        <a name="M000021"></a>

        <div class="method-heading">
          <a href="#M000021" class="method-signature">
          <span class="method-name">has_course?</span><span class="method-args">(course_id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
determines whether the user is taking the course in a semester or in course
bin
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000021-source">
<pre>
    <span class="ruby-comment cmt"># File app/models/user.rb, line 54</span>
54:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_course?</span>(<span class="ruby-identifier">course_id</span>)
55:     <span class="ruby-identifier">semesters</span>.<span class="ruby-identifier">collect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">semester</span><span class="ruby-operator">|</span>
56:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">semester</span>.<span class="ruby-identifier">cis_courses</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">course_id</span>)
57:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
58:       <span class="ruby-keyword kw">end</span> 
59:     <span class="ruby-keyword kw">end</span>
60:   
61:     <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">course_bin</span>.<span class="ruby-identifier">cis_courses</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">course_id</span>)
62:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000019" class="method-detail">
        <a name="M000019"></a>

        <div class="method-heading">
          <a href="#M000019" class="method-signature">
          <span class="method-name">to_s</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Given Surname
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000019-source">
<pre>
    <span class="ruby-comment cmt"># File app/models/user.rb, line 36</span>
36:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span>
37:     <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">first_name</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot; &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">last_name</span>
38:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>